﻿using Model.Entity;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Model.Dao
{

    public class LoginInfoDao
    {
        private readonly ISqlSugarClient db;
        
        public LoginInfoDao(ISqlSugarClient db)
        {
            this.db = db;
        }

        /**
         * 根据用户id查找登录信息
         */
        public LoginInfo selectLoginInfoByUserId(long userId)
        {
            List<LoginInfo> list = db.Queryable<LoginInfo>()
                .Where(loginInfo => loginInfo.user_id == userId)
                .ToList();
            return list[0];
        }

        /**
         * 插入一条登录信息
         * */
        public int insertLoginInfo(LoginInfo loginInfo)
        {

            return db.Insertable(loginInfo).ExecuteCommand();
        }


        /**
         * 更新登录信息
         */
        public void updateLoginInfo(LoginInfo loginInfo)
        {
            db.Updateable(loginInfo).ExecuteCommand();
        }
    }
}
